package com.xm.xmapp.dialog;

import java.io.Serializable;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.xm.xmapp.R;
import com.xm.xmapp.response.bean.JpushNotifactionResponse;

public class JpushTipDialog extends Dialog {

	public interface JpushDialogOnclick {
		void cacle();

		void go(Data data);

	}

	private JpushDialogOnclick mJpushDialogOnclick;

	public void setmJpushDialogOnclick(JpushDialogOnclick mJpushDialogOnclick) {
		this.mJpushDialogOnclick = mJpushDialogOnclick;
	}

	public static class Data implements Serializable {
		/**
		 * 
		 */
		private static final long serialVersionUID = 7497393770342374799L;
		public String msg_push_content, msg_push_cover, msg_push_title, msg_push_link;
		public int msg_push_sort;
	}

	private JpushNotifactionResponse bean;

	public JpushTipDialog(Activity context, JpushNotifactionResponse bean) {
		super(context, R.style.Dialog);
		this.bean = bean;
	}

	@SuppressLint("InflateParams")
	public void init() {
		LayoutInflater inflater = LayoutInflater.from(getContext());
		View view = inflater.inflate(R.layout.dialog_jpush_tip, null);
		setContentView(view);
		TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
		TextView tv_content = (TextView) view.findViewById(R.id.tv_content);
		final Data data = JSON.parseObject(bean.data, Data.class);
		tv_title.setText(data.msg_push_title);
		tv_content.setText(data.msg_push_content);

		view.findViewById(R.id.iv_go).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dismiss();
				if (mJpushDialogOnclick != null)
					mJpushDialogOnclick.go(data);
			}
		});

		view.findViewById(R.id.iv_dissmiss).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dismiss();
				if (mJpushDialogOnclick != null)
					mJpushDialogOnclick.cacle();
			}
		});

		switch (data.msg_push_sort) {
		case 0:
			view.findViewById(R.id.ll_bg).setBackgroundResource(R.mipmap.jpushbg1);
			break;
		case 1:
			view.findViewById(R.id.ll_bg).setBackgroundResource(R.mipmap.jpushbg1);
			break;
		case 2:
			view.findViewById(R.id.ll_bg).setBackgroundResource(R.mipmap.jpushbg3);
			break;
		case 3:
			view.findViewById(R.id.ll_bg).setBackgroundResource(R.mipmap.jpushbg2);
			break;

		default:
			break;
		}

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		init();

	}

}
